home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Frontier 4.2.3 / UserLand Utilities / uBASE / uBASE Docs / Read Me < prev   
Text File  |  1996-04-02  |  8KB  |  179 lines

  1. <html>
  2.  
  3. <head>
  4.  
  5. <title>uBASE</title>
  6.  
  7. <body bgcolor="#FFFFFF" text="#000000" link="#0000CC" vlink="#AA0000">
  8.  
  9.  
  10. <h4>[<a href="http://www.hotwired.com/userland/aretha/">Home</a>] Created 5/23/95 by <a href="mailto:dwiner@well.com">dwiner@well.com</a> (Dave Winer)</h4>
  11.  
  12. <h1><img src = "plain.gif" alt = "" align=top> uBASE</h1>
  13.  
  14. <blockquote>
  15. <b>What is uBASE?<p></b>
  16.  
  17. uBASE is a fast flat-file database for script writers.<p>
  18.  
  19. Unlike FileMaker, 4th Dimension and FoxBase, uBASE is designed to serve scripts, not users. It has almost no user interface. It's a very small program that loads quickly. It has a very simple scripting interface. uBASE is ideal for the data storage needs of many scripts.<p>
  20.  
  21. In terms of its Apple Event interface, nothing as fancy as the object model here, just a few simple verbs to create a new file, open an existing file, add a record, lookup a record, close a file. <p>
  22.  
  23. <b>Creating a new file<p></b>
  24.  
  25. The following sections review the scripting verbs for uBASE. If you want to follow along in Frontier, navigate to system.verbs.apps.ubase and open the examples table. Also, all of uBASE's verbs are documented in the DocServer database.<p>
  26.  
  27. To create a new uBASE file, use the ubase.newFile verb. It takes a single parameter, the full path to the file it creates. The file is created initially with no fields and no records. Here's an example:<p>
  28.  
  29. <table>
  30. <td><code><pre>
  31. fnum = ubase.newFile ("System:States Database")
  32. </pre></code></td>
  33. </table><p>
  34.  
  35. ubase.newFile returns a file refnum -- a number between 1 and 99. Save the refnum in a local variable. All subsequent calls to uBASE will use this number. This allows uBASE to manage more than a single open database, and allows scripts to move information from one database to another.<p>
  36.  
  37. <b>Opening an existing file; closing files<p></b>
  38.  
  39. To open an existing file use ubase.openFile. It takes a full path to the file to open, and returns a file refnum:<p>
  40.  
  41. <code><pre>
  42. fnum = ubase.openFile ("System:States Database")
  43. </pre></code><p>
  44.  
  45. To close a uBASE file, use ubase.closeFile:
  46. <code><pre>
  47. ubase.closeFile (fnum)
  48. </pre></code><p>
  49.  
  50. <b>Adding fields to a uBASE file<p></b>
  51.  
  52. After creating a new file or opening an existing file, you can add fields to the database using the ubase.addField verb.<p>
  53.  
  54. ubase.addField takes three parameters:<p>
  55.  
  56. 1.    a file refnum indicating which file the field is to be added to.<p>
  57.  
  58. 2.    fieldName, a four-character string, the name of the field. See note below.<p>
  59.  
  60. 3.    fieldType, a four-character string, indicating the type of the new field.<p>
  61.  
  62. For performance, we limited field names to four characters so that records could flow quickly between uBASE and Frontier using the Apple Event Manager.<p>
  63.  
  64. <b>Field types<p></b>
  65.  
  66. The set of field types supported by uBASE is a subset of the types supported by Frontier. <p>
  67.  
  68. Here's a list of field types:
  69. <pre><code>
  70. booleanType   true or false.
  71. longType      32-bit signed number.
  72. dateType      the number of seconds since Jan 1, 1904.
  73. stringType    a variable length text handle.
  74. doubleType    double-precision floating point number.
  75. binaryType    unformatted data, variable-length.
  76. </code></pre><p>
  77.  
  78. <b>Example<p></b>
  79.  
  80. Here's an example that launches uBASE, creates a new file in the same folder as the Frontier application, adds two string fields to it, and then closes the file:
  81. <code><pre>
  82. local (ubasefolder, fnum)
  83. ubase.launch () <<make sure uBASE is ready to talk to us
  84. fnum = ubase.newFile (Frontier.pathstring + "States Database")
  85. ubase.addField (fnum, 'capi', stringType) <<the state's capital
  86. ubase.addField (fnum, 'abbr', stringType) <<the abbreviation for the state
  87. ubase.closeFile (fnum) <<the database has two fields, no records
  88. </code></pre><p>
  89.  
  90. <b>Each record has a key<p></b>
  91.  
  92. Every record in a uBASE file has a unique key, a string of any number of characters. In an address book application, for example, the key could be a user's email account name. Or in an application database, it could be the creator ID of the application.<p>
  93.  
  94. If you add a record that has the same key as an existing record, the new record replaces the previous record. The key is unique, that's an absolute rock-hard rule.<p>
  95.  
  96. <b>How to add a record to a uBASE file<p></b>
  97.  
  98. ubase.addRecord takes three parameters:<p>
  99.  
  100. 1.    a file refnum;<br>
  101. 2.    the record's key;<br>
  102. 3.    the address of a Frontier table containing the values for the record.<br><p>
  103.  
  104. Here's an example that opens the database created in the previous example and adds a record describing Wisconsin:
  105. <code><pre>
  106. local (fnum, holder)
  107. new (tableType, @holder)
  108. holder.capi = "Madison"
  109. holder.abbr = "WI"
  110. ubase.launch ()
  111. fnum = ubase.openFile (Frontier.pathstring + "States Database")
  112. ubase.addRecord (fnum, "Wisconsin", @holder)
  113. ubase.closeFile (fnum) <<the database has two fields, one record
  114. </code></pre><p>
  115.  
  116. See ubase.examples.addStates for an example that adds all 50 states to the database.<p>
  117.  
  118. <b>ubase.lookupRecord<p></b>
  119.  
  120. The flipside of ubase.addRecord is ubase.lookupRecord. It takes three parameters: a file refnum, the record's key and the address of a Frontier table to receive the values for the record with the indicated key.<p>
  121.  
  122. Here's an example that opens the database and looks up information about Wisconsin:
  123. <code><pre>
  124. local (fnum, holder)
  125. ubase.launch ()
  126. fnum = ubase.openFile (Frontier.pathstring + "States Database")
  127. ubase.lookupRecord (fnum, "Wisconsin", @holder)
  128. ubase.closeFile (fnum)
  129. dialog.alert ("Wisconsin's capital is " + holder.capi + ", abbreviation is " + holder.abbr + ".")
  130. </code></pre><p>
  131.  
  132. See ubase.examples.checkStates for another example.<p>
  133.  
  134. <b>Visiting all the records in a database<p></b>
  135.  
  136. Use ubase.countRecords, ubase.getFirstRecord and ubase.getNextRecord. <p>
  137.  
  138. The records are not sorted. The first record is not necessarily the first record in alphabetic order. It would be much slower to return them in sorted order. Even so, visiting all the records in a database is not a fast operation when compared to a single call to ubase.lookupRecord.<p>
  139.  
  140. Here's an example that displays the names of all 50 states in Frontier's main window:
  141. <code><pre>
  142. local (ubasefolder, fnum, count, key, i)
  143. ubase.launch ()
  144. fnum = ubase.openFile (Frontier.pathstring + "States Database")
  145. count = ubase.countRecords (fnum)
  146. key = ubase.getFirstRecord (fnum)
  147. for i = 1 to count 
  148. msg (key)
  149. key = ubase.getNextRecord (fnum, key)
  150. ubase.closeFile (fnum)
  151. </code></pre><p>
  152.  
  153. For another example, see ubase.examples.reportStates.<p>
  154.  
  155. <b>How uBASE is implemented<p></b>
  156.  
  157. Records are variable-length. There's no need to set a maximum length for string fields. Only the number of characters present in an individual field are stored in the database. The same is true for binary fields.<p>
  158.  
  159. Garbage collection is incremental, when you delete a record, uBASE attempts to merge it with adjacent free blocks. uBASE will re-use space released by deleted records, but the file will never decrease in size.<p>
  160.  
  161. uBASE is an ordinary Apple Event-aware Macintosh application.<p>
  162.  
  163. <b>Version 1.1b1 -- 1/4/96 DW<p></b>
  164.  
  165. uBASE now flushes the default volume after every addRecord, deleteRecord and addField call. Since uBASE often runs on web servers, and web servers sometimes crash, we need to be extra careful with the databases. People were working around this by closing and then re-opening the databases after every addRecord call. It should be faster than closing and reopening the file and safer against system crashes.<p>
  166. </blockquote>
  167.  
  168. <h6>
  169. <hr size=3>
  170. <center>
  171. <center><img src = "frondoc.gif" alt = "" align=center></center><p><p>© copyright 1995-96 UserLand Software Inc. All rights reserved.<p>This page was last updated on Thu, Jan 4, 1996 at 10:51:58 AM. It was created with UserLand Software's <a href = "http://www.hotwired.com/userland/yabbadabba/">Clay Basket</a> website management software.This comment was generated by a <a href = "http://www.hotwired.com/userland/aretha/">Frontier</a> script.
  172. </center>
  173. <hr size=3>
  174. </h6>
  175.  
  176. </body>
  177.  
  178. </html>
  179.